﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Threading;
using Microsoft.Expression.Interactivity.Core;
using System.Windows.Input;

namespace Twittit.WPF
{
    public class MainViewModel : INotifyPropertyChanged
    {

        public event PropertyChangedEventHandler PropertyChanged;

       private void Raise(string propName){
            if(PropertyChanged != null){
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
            }
       }


       public MainViewModel()
        {

           ServiceReferenceUser.ServiceUserClient client = new ServiceReferenceUser.ServiceUserClient();
           int i = 4;

           //List<Twittit.DataAccess.Twit> listTwitts = client.GetUserTwitts(i);

           List<Twittit.DataAccess.Twit> listTwitts = Twittit.Business.UserService.getInstance().getUserTwitts(i);
           Twitts = new ObservableCollection<DataAccess.Twit>(listTwitts);

           
           
        }

       // public void SearchHandler(){
        //    isLoading = true;
       //     ServiceReferenceUser.ServiceUserClient client = new ServiceReferenceUser.ServiceUserClient();
          //  client.GetUserCompleted += new EventHandler<ServiceReferenceUser.GetUserCompletedEventArgs>(client_GetUserCompleted);
           // client.GetUserAsync(StrSearch);
       // }

       // void client_GetUserCompleted(object sender, GetUserCompletedEventArgs e){
       //     Twitts = new ObservableCollection<DataAccess.Twit>(e.Result);
       //     isLoading = false;
       // }

      //  private bool isLoading;
      //  public ICommand Search { get; set; }
 
        private string _strSearch;
        public string StrSearch 
        {
            get{return _strSearch;}
            set{_strSearch=value; Raise("StrSearch");}
        }


        private ObservableCollection<Twittit.DataAccess.Twit> _twitts;
        public ObservableCollection<Twittit.DataAccess.Twit> Twitts{
            get{ return _twitts; }
            set{ _twitts =  value; Raise("Twitts"); }
        }


        public ICommand SaveTwitt
        {
            get
            {
                if (_saveTwitt == null)
                {
                    _saveTwitt = new RelayCommand(){
                        param => this.SaveTwitt(),
                        param => this.CanTwitt()
                    };
                }
                return _saveTwitt;
            }
        }

        private bool canSave(){
            return true;
        }

        private void SaveTwitt(){
            
        }

    }
}
